package com.ice.tools;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.ice.entity.ReceiveXmlEntity;

import com.ice.common.IceLog;

public class GenerateResponseXml {
	
	public static String xml(ReceiveXmlEntity entity){
		
		Document document = DocumentHelper.createDocument();
		Element rootElement = document.addElement("xml");
		
		
		Element toUserNameElement =rootElement.addElement("ToUserName");
		toUserNameElement.addCDATA(entity.getFromUserName());
		
		Element fromUserNameElement = rootElement.addElement("FromUserName");
		fromUserNameElement.addCDATA(entity.getToUserName());
		
		Element createTimeElement=rootElement.addElement("CreateTime");
		createTimeElement.addCDATA(IceLog.getTime());
		
		Element msgTypeElement=rootElement.addElement("MsgType");
		msgTypeElement.addCDATA(entity.getMsgType());
		
		Element contentElement=rootElement.addElement("Content");
		contentElement.addCDATA(entity.getContent());
	 
		
	    return document.asXML().replaceFirst("<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>", "");
	}
}
